import { number } from "mathjs";

const { ccclass, property} = cc._decorator;

@ccclass
export default class Supply extends cc.Component {

    @property
    type:number=0;

    onLoad(){
        this.change();
    }

    reset(){
        if(Math.random()>0.66){
            this.type=1;
        }
        else{
            this.type=0;
        }
        this.change();
    }

    change(){
        switch(this.type){
            case 0:
                this.node.color=cc.Color.fromHEX( this.node.color,'#8A83FF');
            break;
            case 1:
                this.node.color=cc.Color.fromHEX( this.node.color,'#DF8431');
            break;
        }
    }

    onBeginContact(contact, self: cc.Collider, other: cc.Collider) {
        if(other.node.group=='player'){
            switch(this.type){
                case 0:
                    other.node.emit('get-supply',300);
                break;
                case 1:
                    other.node.emit('get-lift',1);
                break
            }
            this.node.destroy();
        }
    }
}
